################################################################################################################
# 基础全字段查询（匹配所有文档）
curl -X POST "http://43.136.170.102:9200/ecommerce_products_java/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "match_all": {}
  },
  "size": 2  // 返回前2条文档
}'

################################################################################################################
# 包含所有字段的详细查询（显式指定字段）
curl -X POST "http://43.136.170.102:9200/ecommerce_products_java/_search" -H 'Content-Type: application/json' -d'
{
  "_source": {
    "includes": [
      "product_id",
      "name",
      "description",
      "price",
      "cost",
      "discount",
      "stock",
      "is_active",
      "created_at",
      "updated_at",
      "categories",
      "tags",
      "location",
      "weight",
      "dimensions",
      "manufacturer",
      "sales_data",
      "attributes",
      "specifications",
      "reviews",
      "variants"
    ]
  },
  "query": {
    "match_all": {}
  }
}'

################################################################################################################
# 嵌套字段查询示例 01 查询嵌套字段 attributes（需使用 nested 查询）：
curl -X POST "http://43.136.170.102:9200/ecommerce_products_java/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "nested": {
      "path": "attributes",
      "query": {
        "bool": {
          "must": [
            { "match": { "attributes.name": "color" } },
            { "term": { "attributes.is_visible": true } }
          ]
        }
      }
    }
  }
}'

################################################################################################################
# 嵌套字段查询示例 02 查询嵌套字段 reviews（筛选评分≥4的评论）：
curl -X POST "http://43.136.170.102:9200/ecommerce_products_java/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "nested": {
      "path": "reviews",
      "query": {
        "range": {
          "reviews.rating": { "gte": 4 }
        }
      }
    }
  }
}'

################################################################################################################
# 复杂组合查询（全字段+条件过滤）
curl -X POST "http://43.136.170.102:9200/ecommerce_products_java/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "must": [
        { "match": { "name": "copper" } },          // 名称包含"copper"
        { "range": { "price": { "lte": 300 } } }    // 价格≤300
      ],
      "filter": [
        { "term": { "is_active": true } },          // 仅活跃商品
        { "range": { "sales_data.last_30_days": { "gt": 100 } } } // 最近30天销量>100
      ]
    }
  },
  "sort": [
    { "created_at": { "order": "desc" } }           // 按创建时间降序
  ]
}'

################################################################################################################
# 聚合分析示例（按分类统计平均价格）
curl -X POST "http://43.136.170.102:9200/ecommerce_products_java/_search" -H 'Content-Type: application/json' -d'
{
  "size": 0,
  "aggs": {
    "categories_stats": {
      "terms": { "field": "categories" },            // 按分类分组
      "aggs": {
        "avg_price": { "avg": { "field": "price" } } // 计算平均价格
      }
    }
  }
}'
